// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Requests;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using Elastic.Transport.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Security;

public sealed partial class GetTokenRequestParameters : RequestParameters
{
}

/// <summary>
/// <para>
/// Creates a bearer token for access without requiring basic authentication.
/// </para>
/// </summary>
public sealed partial class GetTokenRequest : PlainRequest<GetTokenRequestParameters>
{
	internal override ApiUrls ApiUrls => ApiUrlLookup.SecurityGetToken;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "security.get_token";

	[JsonInclude, JsonPropertyName("grant_type")]
	public Elastic.Clients.Elasticsearch.Security.AccessTokenGrantType? GrantType { get; set; }
	[JsonInclude, JsonPropertyName("kerberos_ticket")]
	public string? KerberosTicket { get; set; }
	[JsonInclude, JsonPropertyName("password")]
	public string? Password { get; set; }
	[JsonInclude, JsonPropertyName("refresh_token")]
	public string? RefreshToken { get; set; }
	[JsonInclude, JsonPropertyName("scope")]
	public string? Scope { get; set; }
	[JsonInclude, JsonPropertyName("username")]
	public Elastic.Clients.Elasticsearch.Username? Username { get; set; }
}

/// <summary>
/// <para>
/// Creates a bearer token for access without requiring basic authentication.
/// </para>
/// </summary>
public sealed partial class GetTokenRequestDescriptor : RequestDescriptor<GetTokenRequestDescriptor, GetTokenRequestParameters>
{
	internal GetTokenRequestDescriptor(Action<GetTokenRequestDescriptor> configure) => configure.Invoke(this);

	public GetTokenRequestDescriptor()
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.SecurityGetToken;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "security.get_token";

	private Elastic.Clients.Elasticsearch.Security.AccessTokenGrantType? GrantTypeValue { get; set; }
	private string? KerberosTicketValue { get; set; }
	private string? PasswordValue { get; set; }
	private string? RefreshTokenValue { get; set; }
	private string? ScopeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Username? UsernameValue { get; set; }

	public GetTokenRequestDescriptor GrantType(Elastic.Clients.Elasticsearch.Security.AccessTokenGrantType? grantType)
	{
		GrantTypeValue = grantType;
		return Self;
	}

	public GetTokenRequestDescriptor KerberosTicket(string? kerberosTicket)
	{
		KerberosTicketValue = kerberosTicket;
		return Self;
	}

	public GetTokenRequestDescriptor Password(string? password)
	{
		PasswordValue = password;
		return Self;
	}

	public GetTokenRequestDescriptor RefreshToken(string? refreshToken)
	{
		RefreshTokenValue = refreshToken;
		return Self;
	}

	public GetTokenRequestDescriptor Scope(string? scope)
	{
		ScopeValue = scope;
		return Self;
	}

	public GetTokenRequestDescriptor Username(Elastic.Clients.Elasticsearch.Username? username)
	{
		UsernameValue = username;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (GrantTypeValue is not null)
		{
			writer.WritePropertyName("grant_type");
			JsonSerializer.Serialize(writer, GrantTypeValue, options);
		}

		if (!string.IsNullOrEmpty(KerberosTicketValue))
		{
			writer.WritePropertyName("kerberos_ticket");
			writer.WriteStringValue(KerberosTicketValue);
		}

		if (!string.IsNullOrEmpty(PasswordValue))
		{
			writer.WritePropertyName("password");
			writer.WriteStringValue(PasswordValue);
		}

		if (!string.IsNullOrEmpty(RefreshTokenValue))
		{
			writer.WritePropertyName("refresh_token");
			writer.WriteStringValue(RefreshTokenValue);
		}

		if (!string.IsNullOrEmpty(ScopeValue))
		{
			writer.WritePropertyName("scope");
			writer.WriteStringValue(ScopeValue);
		}

		if (UsernameValue is not null)
		{
			writer.WritePropertyName("username");
			JsonSerializer.Serialize(writer, UsernameValue, options);
		}

		writer.WriteEndObject();
	}
}